<?php 
	
namespace app\admin\validate;
//导入Validate类
use think\Validate;
use think\Db;

class OrganizeDept extends Validate{
	protected $rule=[
		'name'=>'require|checkBlockName',
	];

	protected $message=[
		'name.require'=>'部门名不能为空',
		'name.checkBlockName'=>'部门名重复,请重新输入',
	];

	public function checkBlockName($value, $rule, $data) 
    {
        $where = [
            'name' => $value,
            'org_id' => $data['org_id']
        ];
        if (isset($data['id'])) {
            $where['id'] = ['neq', $data['id']];
        }
        $lists = Db::name('dept')->where($where)->find();
        
        return $lists ? false : true;
    }

} 

 ?>